package nioTest;

import java.nio.ByteBuffer;

/**
 * 名称: SliceBufferTest.java <br>
 * 描述: <br>
 * 最近修改时间:2018/5/21 11:26 <br>
 *
 * @version [版本号, V1.0]
 * @since 2018/5/21 11:26
 * @author zhipingzhang  
 */
public class SliceBufferTest {

    public static void main(String[] args) {

        ByteBuffer byteBuffer = ByteBuffer.allocate(10);

        for(int i = 0 ;i < byteBuffer.capacity();++i){
            byteBuffer.put(i,(byte) i);
        }

        byteBuffer.position(3);
        byteBuffer.limit(7);

        ByteBuffer sliceBuffer = byteBuffer.slice();

        System.out.println(sliceBuffer);
        for(int i = 0 ;i < sliceBuffer.capacity();++i){
            byte b = sliceBuffer.get(i);
            b*=10;
            sliceBuffer.put(i,b);
        }

        byteBuffer.position(0);
        byteBuffer.limit(byteBuffer.capacity());

        while (byteBuffer.hasRemaining()){
            System.out.println(byteBuffer.get());
        }


    }
}
